//
//  AppDelegate.m
//  XKJY
//
//  Created by Mr.xu on 2017/1/10.
//  Copyright © 2017年 xiaokang100. All rights reserved.
//

#import "AppDelegate.h"
#import "AppDelegate+Config.h"
#import "AppDelegate+RootController.h"
#import "AppDelegate+Version.h"

// 友盟组件
#import "AppDelegate+USocial.h"
#import "AppDelegate+UMessage.h"
#import "AppDelegate+UAnalytics.h"


@interface AppDelegate ()

@end

@implementation AppDelegate

#pragma mark - 横竖屏控制
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
    if (_allowRotation == 1) {
        return UIInterfaceOrientationMaskLandscapeRight;
    } else {
        return UIInterfaceOrientationMaskPortrait;
    }
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    // 服务器查看
//    [self checkAppVersion];
    // 启动睡眠
    [NSThread sleepForTimeInterval:0];
    
    // 根控制器
    [self setRootViewController];
    
    // 其他第三方配置
    [self configs];
    
    // 友盟
    [self startUmengSocial];
    [self startUmengAnalytics];
    [self startUmengMessageWithLaunchOptions:launchOptions];
    
    
    return YES;
}

/************************************************************************************************************************/
- (void)applicationWillResignActive:(UIApplication *)application {
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
}

- (void)applicationWillTerminate:(UIApplication *)application {
}
/************************************************************************************************************************/




// iOS 9 以上请用这个
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options {
    return [Pingpp handleOpenURL:url withCompletion:nil];
}


- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    // 1.2.7版本开始不需要用户再手动注册devicetoken，SDK会自动注册
//    [UMessage registerDeviceToken:deviceToken];
    
    NSString *user_deviceToken = [[[[deviceToken description] stringByReplacingOccurrencesOfString: @"<" withString: @""]
                  stringByReplacingOccurrencesOfString: @">" withString: @""]
     stringByReplacingOccurrencesOfString: @" " withString: @""];
    
    NSLog(@"*******************************************************************\n%@\n*******************************************************************",user_deviceToken);
    
    [UserDefaults setObject:user_deviceToken withKey:@"push_deviceToken"];
    
}


@end
